package geometrie;

public class Punkt
{
    private int xKoordinate;

    private int yKoordinate;

    public int getXKoordinate()
    {
        return xKoordinate;
    }

    public void setXKoordinate(int xKoordinate)
    {
        this.xKoordinate = xKoordinate;
    }

    public int getYKoordinate()
    {
        return yKoordinate;
    }

    public void setYKoordinate(int yKoordinate)
    {
        this.yKoordinate = yKoordinate;
    }

    public Punkt(int xKoordinate, int yKoordinate)
    {
        this.xKoordinate = xKoordinate;
        this.yKoordinate = yKoordinate;
    }

    public Punkt(Punkt p2)
    {
        if (p2 != null)
        {
            p2 = new Punkt(p2.xKoordinate, p2.yKoordinate);
        }
        else
        {
            p2 = new Punkt(0, 0);
        }
    }

    public double abstand(Punkt p) throws NullPointerException
    {
        try
        {
            return Math.sqrt(Math.pow(p.xKoordinate - xKoordinate, 2) + Math.pow(p.yKoordinate - yKoordinate, 2));
        }
        catch (NullPointerException e)
        {
            System.out.println("Fehler");
            return Double.NaN;
        }

    }

    public void verschieben(int deltaX, int deltaY)
    {
        xKoordinate += deltaX;
        yKoordinate += deltaY;
    }

    public boolean equals(Punkt p1)
    {
        if (p1.xKoordinate == xKoordinate && p1.yKoordinate == yKoordinate)
        {
            return true;
        }
        return false;
    }

    public Punkt maximum(Punkt p)
    {
        if (p != null)
        {
            if (Math.sqrt(p.xKoordinate * p.xKoordinate + p.yKoordinate * p.yKoordinate) > Math.sqrt(xKoordinate * xKoordinate + yKoordinate * yKoordinate))
            {
                return p;
            }
        }
        return Punkt.this;
    }

}
